﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Regions;
using MP3Ganizer.Modules.DirectoryLoader.ViewModels;
using MP3Ganizer.Common;
using MP3Ganizer.Common.Interfaces.DirectoryLoader;
using MP3Ganizer.Common.BaseObject;
using Microsoft.Practices.Composite.Events;
using MP3Ganizer.Modules.DirectoryLoader.Views;

namespace MP3Ganizer.Modules.DirectoryLoader.Controllers
{
  /// <summary>
  /// Controller du DirectoryLoader
  /// </summary>
    public class DirectoryLoaderController : ModuleControllerBase, IDirectoryLoaderController
  {
    #region Fields
    private readonly IUnityContainer _container;
    private readonly IRegionManager _regionManager;
    private readonly IDirectoryLoaderViewModel _directoryLoaderMainVM;
    #endregion

    #region Constructor
    /// <summary>
    /// Constructeur. Les paramètres sont pré-remplis par le UnityContainer.
    /// </summary>
    /// <param name="container"></param>
    /// <param name="regionManager"></param>
    /// <param name="DirectoryLoaderMainVM"></param>
    public DirectoryLoaderController(IUnityContainer container, IRegionManager regionManager, IEventAggregator eventAggregator)
        : base(container, regionManager, eventAggregator)
    {
      this._container = container;
      this._regionManager = regionManager;
    }
    #endregion

    #region IDirectoryLoaderMainController Members

    /// <summary>
    /// Lance le Controller: Injecte la vue dans la région
    /// </summary>
    public override void Run()
    {
       
      this._regionManager.RegisterViewWithRegion(RegionNames.Top, 
                                        () => RegisterView());
    }

    private IDirectoryLoaderView RegisterView()
    {
        DirectoryLoaderView view = _container.Resolve<DirectoryLoaderView>();
        DirectoryLoaderViewModel viewModel = (DirectoryLoaderViewModel)view.DataContext;
        viewModel.Initialize();
        return view;
    } 

    #endregion

    protected override void SubscribeCompositeEvent()
    {
        
    }
  }
}
